/**
 * This class represents a product-handler
 * 
 * @author Konrad Paumann
 * @author Bernhard Denner
 * @author Maximilian Csuk
 * 
 * $Revision: 63 $ 
 * $Date: 2007-10-19 17:32:10 +0200 (Fri, 19 Oct 2007) $
 * 
 */

public class ProductHandler extends Handler {
	/**
	 * variables
	 */
	private final Product product;
	
	/**
	 * constructor
	 * @param product the product to handle
	 */
	public ProductHandler(Product product, User user) {
		super(user);
		assert product != null;
		this.product = product;
	}
	
	/**
	 * returns the price, if the user has the appropriate rights
	 * @return the price
	 * @throws UserException
	 */
	public int getPrice() throws UserException {
		if (!user.canRead())
			throw new UserException("User nicht authorisiert");
		return product.getPrice();
	}
	
	/**
	 * sets the price, if the user has the appropriate rights
	 * @param the price
	 * @throws UserException
	 */
	public void setPrice(int price) throws UserException, ProductException {
		if (!user.canWrite())
			throw new UserException("User nicht authorisiert");
		try {
			product.setPrice(price);
		} catch (ProductException e) {
			throw new ProductException(e.getMessage());
		}
	}
	
	
}
